package gui;

import java.awt.FlowLayout;
import java.util.Calendar;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/**
 * A JPanel presenting several options to the user to choose from,
 * aligned as specified by the FlowLayoutManager.
 *
 * @author Manseer Marcel  
 * @author Plavsic Maja
 * @author Pretsch Paul
 */
@SuppressWarnings("serial")
public class TimeFramePicker extends JPanel {
	
	public JRadioButton last24hButton, last3daysButton, lastWeekButton;
		
	public TimeFramePicker() {
		super(new FlowLayout());
	    setBorder(BorderFactory.createTitledBorder("Time frame"));
	    ButtonGroup group = new ButtonGroup();
	    
	    last24hButton = new JRadioButton("last 24h");
	    last3daysButton = new JRadioButton("last 3 days");
	    lastWeekButton = new JRadioButton("last week");
	    
	    group.add(last24hButton);
	    group.add(last3daysButton);
	    group.add(lastWeekButton);
	    
	    add(last24hButton);
	    add(last3daysButton);
	    add(lastWeekButton);
	    
	    lastWeekButton.setSelected(true); //pre-select last week
	}
	
	public Date getSelectedDaySince() {
		Calendar cal = Calendar.getInstance();
		
		if (last24hButton.isSelected()) {
			cal.add(Calendar.DAY_OF_WEEK, -1);
		} else if (last3daysButton.isSelected()) {
			cal.add(Calendar.DAY_OF_WEEK, -3);
		} else {
			cal.add(Calendar.WEEK_OF_YEAR, -1);
		}
		
		return cal.getTime();
	}
}
